# zj812_rule.py
import sys
from pathlib import Path

# 获取 template 目录的绝对路径（根据实际结构调整）
current_file = Path(__file__)
template_dir = current_file.parent.parent  # 上两级目录


sys.path.append(str(template_dir))

# 现在可以正常导入
from utils import date_offset_handler,generate_random_data_with_params
from base_rule import BaseRule
from DataProcessor import DataProcessor
import random
import pandas as pd

class ZJ904_Rule(BaseRule):
    def __init__(self, project_info):
        super().__init__("ZJ904", project_info)

        self.add_field("桩号、部位", lambda p: p['project_info']['施工部位'])
        self.add_field("施工日期", date_offset_handler(0), data_type="date", format="%Y年%m月%d日")
        self.add_field("检验日期", date_offset_handler(30), data_type="date", format="%Y年%m月%d日")
        self.add_field("质检负责人日期", date_offset_handler(30), data_type="date", format="%Y年%m月%d日")
        self.add_field("自检员日期", date_offset_handler(30), data_type="date", format="%Y年%m月%d日")
        
    
    def process(self,**kwargs):
            """
            封装处理逻辑，直接返回结果
            :param data_file_path: 数据文件路径（Excel/CSV）
            :return: 处理后的 DataFrame
            """
            data_file_path=current_file.parent / '模板数据.xlsx'
            df = pd.read_excel(data_file_path)
            rules = self.get_rules()

            processor = DataProcessor(base_data=df, project_info=self.project_info, rules=rules)
            results = processor.process_dataframe(df)

            return results
    